import db from '../config/db.js';
const userModel = '../schema/user.js';
const AddressDb = db.AddressBook;

const User = AddressDb.import(userModel);

const getUserById = async function (id) {
  const userInfo = await User.findOne({
    where: {
      id: id
    }
  });

  return userInfo;
}

const createUser = async function (data) {
  const res = await User.create({
    user_name: data.userName,
    password: data.password,
  });
  return res;
};

const getUserByName = async function (name) {
  const userInfo = await User.findOne({
    where: {
      user_name: name
    }
  })

  return userInfo
};

export default {
  getUserById, // 导出getUserById的方法，将会在controller里调用
  getUserByName,
  createUser
};
